/*******************************************************************************
Graphics.h

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2009-09-15

	Copyright (C) 2009
	All rights reserved.
	
*******************************************************************************/


#ifndef __GRAPHICS_H_
#define __GRAPHICS_H_

struct HGC
{
	int		nWidth;
	int		nHeight;
	void*	pGC;
};

struct GColor
{
	float red;
	float green;
	float blue;
	float alpha;
};

struct GPoint
{
	int	x;
	int y;
};

struct GRect
{
	int x;
	int y;
	int cx;
	int cy;
};

struct GRbox : public GRect
{
	int arc_x;
	int arc_y;
};


struct GArc : public GRect
{
	int	startAngle;
	int	sweepAngle;

	void Normalize();
};


class Graphics
{
public:
	Graphics(HGC hGC);
	~Graphics();

public:
	int	gcWidth()const;
	int	gcHeight()const;

public:
	void SetColor(const GColor& color);

	void DrawPoint(const GPoint& point);
	void DrawPoints(const GPoint* pPoints, int nCount);

	void DrawLine(const GPoint& pt1, const GPoint& pt2);

	void DrawRect(const GRect& rect);
	void FillRect(const GRect& rect);

	void DrawArc(const GArc& arc);
	void FillArc(const GArc& arc);

	void DrawRbox(const GRbox& rbox);
	void FillRbox(const GRbox& rbox);

	void DrawTriangle(const GPoint& pt1, const GPoint& pt2, const GPoint& pt3);
	void FillTriangle(const GPoint& pt1, const GPoint& pt2, const GPoint& pt3);

protected:
	void drawArc(const GArc& arc, bool bFill);
	void setArcProperties(int* ai, int i1, int j1, int k1, int l1);
	void setArcIndexedPixel(int i1, int j1, int k1, int l1,
			int i2, int j2, int k2, int l2, int i3, int j3, 
			int * ai, int length, bool bFill);

	int	m_nMaxClipWidth;
	int m_nMaxClipHeight;

	HGC	m_hGC;
};

#endif // __GRAPHICS_H_
